<?php

namespace App\Http\Controllers;

use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Auth;


trait AuthUserTrait {
  protected function addMiddleWare($exception = []) {
    $prefix = Route::getCurrentRoute()->getPrefix();
    if (preg_match('/api/', $prefix)) {
      $this->middleware('auth:api', $exception);
      $this->isAPI = true;
    } else {
      $this->middleware('auth', $exception);
      $this->isAPI = false;
    }
  }

  protected function isAPIUser() {
    if (!$this->isAPI) {
      return false;
    }
    $user = Auth::guard('api')->user();
    if ($user->name == 'api_user') {
      return true;
    }
    return false;
  }
}